class Share extends eui.Component implements eui.UIComponent {
	public constructor() {
		super();
		this.skinName = ShareSkin;
	}

	protected partAdded(partName: string, instance: any): void {
		super.partAdded(partName, instance);
	}

	private Nametext;	//姓名输入框
	private telText;	//电话输入框
	private callphone;	//验证码输入框
	private submit;		//提交按钮
	private shares;		//分享按钮
	private again;		//再玩一次按钮
	private rank;		//排行榜按钮
	private fenxiang;	//分享朋友圈页面
	private zhongjiang;  //中奖页面
	private paihangbang; //排行榜页面
	private daojishi: number = 60
	private again2;  	//再玩一次按钮
	private xuanyao;   	//炫耀成绩按钮
	private yanzheng;   //验证码kuang
	private huoqu;   //点击获取验证码按钮
	private sumits;  //提交页面
	private shaersuee;    //提交成功页面 分享按钮
	private againssee;	 //提交成功页面 再玩一次按钮
	private paihangsuee;	//提交成功页面 排行榜按钮
	private sumisuccess;    //提交成功页面
	private ziliao;   //填写资料
	private youhui;
	private datu;
	private arr;
	private bizhi;
	// private dabizhi;

	protected childrenCreated(): void {
		super.childrenCreated();

		//随机抽奖
		this.arr = ["result-1_png", "result-2_png", "result-3_png"];
		var arrleng = Math.floor(Math.random() * this.arr.length);
		this.ziliao.source = this.arr[arrleng];

		//点击中奖页面填写资料
		this.ziliao.addEventListener(egret.TouchEvent.TOUCH_TAP, () => {
			if (arrleng == 2) {
				egret.Tween.get(this.sumits).to({ x: 0 }, 300);
				egret.Tween.get(this.zhongjiang).to({ x: -640 }, 50);
			}
			else if (arrleng == 1) {
				egret.Tween.get(this.bizhi).to({ scaleX: 1, scaleY: 1 }, 1000);
			}
			else {
				egret.Tween.get(this.sumits).to({ x: 0 }, 300);
				egret.Tween.get(this.zhongjiang).to({ x: 640 }, 10);
			}

		}, this)
		//点击高清壁纸跳转排行榜页面
		//正则表达式
		var regName = /^[\u4e00-\u9fa5A-Za-z]+$/;
		var regTel = /^1[3-8]\d{9}$/;
		var regYan = /^\d{5}$/;
		this.bizhi.addEventListener(egret.TouchEvent.TOUCH_TAP, () => {
			egret.Tween.get(this.bizhi).to({ scaleX: 0, scaleY: 0 }, 500);
		}, this)
		//点击电话框
		this.telText.addEventListener(egret.TouchEvent.TOUCH_TAP, () => {
			if (regName.test(this.Nametext.text) || this.Nametext.text == " ") {

			} else {
				alert("输入名字不合法")
			}
		}, this)
		//点击获取验证码
		//定时器
		let timer = new egret.Timer(1000, 60)
		timer.addEventListener(egret.TimerEvent.TIMER, () => {
			this.daojishi--
			var ggg = this.daojishi + "s" + "后重发";
			this.huoqu.label = ggg;

		}, this);
		timer.addEventListener(egret.TimerEvent.TIMER_COMPLETE, () => {
			timer.reset()
			this.huoqu.label = "重新发送";
			this.daojishi = 60;
		}, this);
		this.huoqu.addEventListener(egret.TouchEvent.TOUCH_TAP, () => {
			if (regTel.test(this.telText.text)) {
				timer.start()
				XMLHttp.Create().sendPostRequest({
					URL: "http://swin.bluej.cn/index.php/Home/app/verification_code.html ",
					RequestData: { "phone": this.telText.text }, Tokenkey: "lkasdj213489ulkjadsf", MD5: true
				})
			} else {
				alert("输入手机号码不合法")
			}
		}, this)
		this.submit.addEventListener(egret.TouchEvent.TOUCH_TAP, () => {
			egret.Tween.get(this.submit).to({scaleX:1.2,scaleY:1.2},100);
			if (regTel.test(this.telText.text) && regName.test(this.Nametext.text)) {

			} else {
				alert("输入不合法");
			}
		}, this)
		this.submit.addEventListener(egret.TouchEvent.TOUCH_TAP, () => {
			if (regYan.test(this.yanzheng.text)) {
				egret.Tween.get(this.sumisuccess).to({ x: 0 }, 300);
				egret.Tween.get(this.sumits).to({ x: 640 }, 100);
			} else {
				alert("请输入正确的验证码");
			}
		}, this)

		//点击分享成绩跳转到分享页面
		this.shares.addEventListener(egret.TouchEvent.TOUCH_TAP, () => {
			egret.Tween.get(this.fenxiang).to({ y: 0 }, 300);
		})
		this.shaersuee.addEventListener(egret.TouchEvent.TOUCH_TAP, () => {
			egret.Tween.get(this.fenxiang).to({ y: 0 }, 300);

		})
		this.fenxiang.addEventListener(egret.TouchEvent.TOUCH_TAP, () => {
			egret.Tween.get(this.fenxiang).to({ y: -1136 }, 500);
		})
		//点击中奖页面再玩一次跳转到主页页面
		this.again.addEventListener(egret.TouchEvent.TOUCH_TAP, () => {
			SceneManager.createObj(this.stage).loadScene("index", Index);
		}, this)
		this.againssee.addEventListener(egret.TouchEvent.TOUCH_TAP, () => {
			SceneManager.createObj(this.stage).loadScene("index", Index);
		}, this)
		//点击排行榜中的再玩一次按钮跳转到主页页面
		this.again2.addEventListener(egret.TouchEvent.TOUCH_TAP, () => {
			SceneManager.createObj(this.stage).loadScene("index", Index);
		}, this)

		//点击中奖页面中的排行榜按钮跳转到主页页面
		this.rank.addEventListener(egret.TouchEvent.TOUCH_TAP, () => {
			egret.Tween.get(this.paihangbang).to({ x: 0 }, 300);
			egret.Tween.get(this.zhongjiang).to({ x: -640 }, 50);
		}, this)
		this.paihangsuee.addEventListener(egret.TouchEvent.TOUCH_TAP, () => {
			egret.Tween.get(this.paihangbang).to({ x: 0 }, 300);
			egret.Tween.get(this.sumisuccess).to({ x: -640 }, 50);
		}, this)
		//点击排行榜页面中的炫耀页面按钮跳转到分享朋友圈页面
		this.xuanyao.addEventListener(egret.TouchEvent.TOUCH_TAP, () => {
			egret.Tween.get(this.fenxiang).to({ y: 0 }, 300);
		}, this)


	}

}